package com.example.a66666.yuejian.Fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a66666.yuejian.Adapter.GameAdapter;
import com.example.a66666.yuejian.Adapter.MasterAdapter;
import com.example.a66666.yuejian.Bean.GameBean;
import com.example.a66666.yuejian.Bean.MasterBean;
import com.example.a66666.yuejian.Listener.RetrofitListener;
import com.example.a66666.yuejian.Loader.GlideImageLoader;
import com.example.a66666.yuejian.Model.UserModel;
import com.example.a66666.yuejian.R;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class GameFragment extends Fragment {

    private Banner banner;
    private ArrayList<String> listPath;
    private RecyclerView recyclerView;
    private UserModel userModel;
    private RetrofitListener<List<GameBean>> listener;
    private LinearLayoutManager linearLayoutManager;
    private GameAdapter gameAdapter;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_game,container,false);
        gameAdapter=new GameAdapter();
        recyclerView=(RecyclerView)view.findViewById(R.id.gameRecyclerView);
        linearLayoutManager=new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(gameAdapter);
        initBanner(view);
        listener=new RetrofitListener<List<GameBean>>() {
            @Override
            public void onSuccess(List<GameBean> list) {
                gameAdapter.setData(list);
            }

            @Override
            public void onFail(String msg) {

            }
        };

        userModel=new UserModel();
        userModel.getAllGame(listener);
        return view;
    }

    public void initBanner(View view){
        banner=(Banner)view.findViewById(R.id.gameBanner);
        listPath=new ArrayList<>();
        listPath.add("http://10.0.2.2/yuejian/public/static/gameLBT/1.jpg");
        listPath.add("http://10.0.2.2/yuejian/public/static/gameLBT/2.jpg");
        listPath.add("http://10.0.2.2/yuejian/public/static/gameLBT/3.jpg");
        listPath.add("http://10.0.2.2/yuejian/public/static/gameLBT/4.jpg");
        banner.setBannerStyle(BannerConfig.NUM_INDICATOR);
        banner.setImageLoader(new GlideImageLoader());
        banner.setImages(listPath);
        banner.setBannerAnimation(Transformer.DepthPage);
        banner.setDelayTime(2000);
        banner.setIndicatorGravity(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
        banner.start();
    }

}
